package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.EmployeeBean;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("employee")
public class EmployeeController {
    @Autowired
    private IEmployeeService service;
    @RequestMapping("findByItem")
    public String findByItem(@RequestParam(value = "pageNO",defaultValue = "1") Integer pageNO,
                             String position,Integer minSalary,Integer maxSalary,
                             HttpServletRequest req){
        IPage<EmployeeBean> iPage = service.cutByItem(pageNO, position, minSalary, maxSalary);

        req.setAttribute("ipage",iPage);
        req.setAttribute("position",position);
        req.setAttribute("minSalary",minSalary);
        req.setAttribute("maxSalary",maxSalary);

        return "/index.html";
    }
    @RequestMapping("findById")
    public String findById(Integer id ,HttpServletRequest req){
        EmployeeBean em = service.findById(id);
        System.out.println(em);
        req.setAttribute("em",em);
        return "/update.html";
    }

    @RequestMapping("update")
    public String update(Integer id,Integer salary){
        service.upDate(id,salary);
        return "redirect:/employee/findByItem";
    }
    @RequestMapping("add")
    public String add(EmployeeBean em){
        service.add(em);
        return "redirect:/employee/findByItem";
    }
    @RequestMapping("del")
    public String del(Integer id){
        service.del(id);
        return "redirect:/employee/findByItem";
    }
}
